define('pagination',['jquery'],function($) {
	/*---分页---*/
	function My_Pagination(options){
		var opts = {
			pageSize:10,
			page_arr:[10,20,30,50,100,150],
			container:'.pagination',
			callback:function(){return false;}
		};
		$.extend(opts,options||{});
		this.currentPage = 1;
		this.container = $(opts.container);
		this.pageSize = 10;
		this.numPages = 1;
		this.queryConditions = {};//查询条件
		this.callback = opts.callback;
		this.initDom(opts);
		this.initEvents();
	};
	My_Pagination.prototype.initDom = function(opts){//初始化分页内容
		var self = this;
		var shtml = '<span class="paginsplit select"><select>';
		for(var i=0,len=opts.page_arr.length;i<len;i++){
			shtml +='<option value="'+opts.page_arr[i]+'">'+opts.page_arr[i]+'</option>';
		}
		shtml+='</select></span>'+
			'<span class="paginsplit swichblock icon1"></span>'+
		    '<span class="paginsplit swichblock icon2"></span>'+
			'<span class="paginsplit"><em>第<input type="text" class="number" value="1">页 共<i class="numPages">1</i>页</em></span>'+
		    '<span class="paginsplit swichblock icon3"></span>'+
		    '<span class="paginsplit swichblock icon4"></span>'+
		    '<span class="paginsplit swichblock icon5"></span>';
		self.container.html(shtml);
		self.container.find('select').val(opts.pageSize);
		self.goSearch();
	};
	My_Pagination.prototype.initEvents = function(){
		var self = this;
		self.container.on('change','select',function(){//每页条数
			self.pageSize = $(this).val();
			self.callback();
		}).on('change','input.number',function(){//跳转
			var newCurrPage = $(this).val();
			if(newCurrPage<=self.numPages && newCurrPage>1){
				self.currentPage = newCurrPage;
				self.callback();
			}else{
				$(this).val(self.currentPage);
			}
		}).on('click','.paginsplit.icon1',function(){//首页
			if(self.currentPage!=1){
				self.currentPage = 1;
				self.jumpTo();
			}
		}).on('click','.paginsplit.icon2',function(){//上一页
			if(self.currentPage>1){
				self.currentPage--;
				self.jumpTo();
			}
		}).on('click','.paginsplit.icon3',function(){//下一页
			if(self.currentPage<self.numPages){
				self.currentPage++;
				self.jumpTo();
			}
		}).on('click','.paginsplit.icon4',function(){//最后一页
			if(self.currentPage!=self.numPages){
				self.currentPage = self.numPages;
				self.jumpTo();
			}
		}).on('click','.paginsplit.icon5',function(){//刷新
			self.callback();
		});
	};
	My_Pagination.prototype.refreshPageNum = function(total){//刷新页码
		var self = this;
		self.numPages = 1;
		if(total>0){
			self.numPages = Math.ceil(total/self.pageSize);
			if(self.currentPage>self.numPages){
				self.currentPage = self.numPages;
				self.callback();
				return false;
			}
		}
		self.container.find('i.numPages').text(self.numPages);
		self.container.find('input.number').val(self.currentPage);
	};
	My_Pagination.prototype.jumpTo = function(){//跳转到
		var self = this;
		self.container.find('input.number').val(self.currentPage);
		self.callback();
	};
	My_Pagination.prototype.goSearch = function(){//点击搜索执行
		var self = this;
		self.currentPage = 1;
		self.jumpTo();
	};
	return My_Pagination;
});